package btd.game.dlgs;

import btd.game.ConstData;
import btd.game.activities.PBoardAct;
import btd.game.activities.R;
import btd.game.activities.SdeskAct;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ChatInputDlg extends Dialog {
	private EditText etChatInfo = null;
	private Button bOK = null;
	private Button bConstText1 = null;
	private Button bConstText2 = null;
	private Button bBack = null;
	private String info = "";
	private Activity owner = null;
	private boolean isSdeskAct = false;
	public ChatInputDlg(Context context, boolean isSdeskAct) {
		super(context);
		this.isSdeskAct = isSdeskAct;
		if(isSdeskAct) {
		    owner = (SdeskAct) context;
		} else {
			owner = (PBoardAct) context;
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.chatinputdlg);
		this.setTitle(R.string.consttext);
		
		etChatInfo = (EditText) findViewById(R.id.EditTextChatInputDlgNewInfo);
		bOK = (Button) findViewById(R.id.ButtonChatInputDlgOK);
		bConstText1 = (Button) findViewById(R.id.ButtonChatInputDlgConstText1);
		bConstText2 = (Button) findViewById(R.id.ButtonChatInputDlgConstText2);
		bBack = (Button) findViewById(R.id.ButtonChatInputDlgBack);
		
		bOK.setOnClickListener(okListener);
		bConstText1.setOnClickListener(ct1Listener);
		bConstText2.setOnClickListener(ct2Listener);
		bBack.setOnClickListener(backListener);
	}
	
	private View.OnClickListener okListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			info = etChatInfo.getText().toString();
			if(isSdeskAct) {
				((SdeskAct) owner).setChatInfo(info);
			} else {
				((PBoardAct) owner).setChatInfo(info);
			}
			ChatInputDlg.this.cancel();
		}
	};
	
	private View.OnClickListener ct1Listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			ChatInputDlg.this.cancel();
			ConstData.updateLanguage(owner);
			new ConstTextListDlg(owner, isSdeskAct, true).show();
		}
	};
	
	private View.OnClickListener ct2Listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			ChatInputDlg.this.cancel();
			ConstData.updateLanguage(owner);
			new ConstTextListDlg(owner, isSdeskAct, false).show();
		}
	};
	
	private View.OnClickListener backListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			ChatInputDlg.this.cancel();
		}
	};
}
